package com.grq.framework.core.exception;

import cn.hutool.http.HttpStatus;
import com.grq.framework.core.enums.ResultEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常类
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BusinessException extends RuntimeException {

    /**
     * 业务代码
     */
    private Integer code = HttpStatus.HTTP_INTERNAL_ERROR;
    /**
     * 异常信息
     */
    private String msg;

    public BusinessException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public BusinessException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(ResultEnum result) {
        super(result.getMsg());
        this.code = result.getCode();
        this.msg = result.getMsg();
    }

    public BusinessException(ResultEnum result, String msg) {
        super(msg);
        this.code = result.getCode();
        this.msg = msg;
    }

    @Override
    public String getMessage() {
        return "[" + code + "]" + msg;
    }

}
